﻿using Application.AppService.JurisdictionAppService;
using Application.AppService.RolesAppService;
using Application.AppService.RolesJurisdictionAppService;
using AutoMapper;
using Domain;
using Domain.Entity;
using Domain.Repository;
using Microsoft.AspNetCore.Mvc;
using System.Data;

namespace UI.Controllers.authority_management_权限管理_
{
	public class RolesController : Controller
	{
		private readonly IRolesAppService rolesAppService;
		private readonly IMapper mapper;
        private readonly IJurisdictionAppService jurisdictionAppService;
        private readonly IRolesJurisdictionAppService rolesJurisdictionAppService;

        public RolesController(IRolesAppService rolesAppService,IMapper mapper, IJurisdictionAppService jurisdictionAppService, IRolesJurisdictionAppService rolesJurisdictionAppService)
        {
			this.rolesAppService = rolesAppService;
			this.mapper = mapper;
            this.jurisdictionAppService = jurisdictionAppService;
            this.rolesJurisdictionAppService = rolesJurisdictionAppService;
        }
        public IActionResult Index()
		{
			return View();
		}
		public IActionResult Index1()
		{
			return View();
		}
		public IActionResult Index2()
		{
			return View();
		}
		public IActionResult RoleFenYe(int page, int pageSize)
		{
			RolesFenYe rfy = rolesAppService.RolesData(page, pageSize);
			return Json(rfy);
		}
		public async Task<IActionResult> RolesAdd(Roles roles)
		{
			bool i = await rolesAppService.RolesAdd(roles);
			return Json(i);
		}
		public async Task<IActionResult> RolesDelete(int id)
		{
			bool i = await rolesAppService.RolesDelete(id);
			return Json(i);
		}
		[HttpGet("RolesGet")]
		public async Task<IActionResult> RolesGet()
		{
			List<Roles> roles = await rolesAppService.GetRoles();
			return Json(roles);
		}

        [HttpPost("ShuZhuangTu")]
        public IActionResult ShuZhuangTu()
        {
            List<ShuZhuangTu> shuZhuangTus = jurisdictionAppService.GetShuZhuangTu();
            return Json(shuZhuangTus);
        }

		public async Task<IActionResult> RolesUpdate(Roles roles)
		{
			bool i = await rolesAppService.RolesUpDate(roles);
			return Json(i);
		}

		[HttpPost("GetRolesJurisdiction")]
		public IActionResult GetRolesJurisdiction(int rid)
		{
			List<RolesJurisdiction> i = rolesJurisdictionAppService.GetRolesJurisdiction(rid);
            return Json(i);
        }

        [HttpPost("DeleteRolesJurisdiction")]
        public async Task<IActionResult> DeleteRolesJurisdiction(int rid)
        {
            bool i = await rolesJurisdictionAppService.DeleteRolesJurisdictionAsync(rid);
            return Json(i);
        }

       [HttpPost("AddRolesJurisdiction")]
        public async Task<IActionResult> AddRolesJurisdiction(int rid ,int jid)
        {
            bool i = await rolesJurisdictionAppService.AddRolesJurisdictionAsync(rid,jid);
            return Json(i);
        }
    }
}
